import ObjectParser from "../ObjectParser.js";

const mimeType = {
    html: "text/html",
    svg: "image/svg+xml",
    xml: "application/xml",
};
class HTMLParser extends ObjectParser {
    constructor(params = {}) {
        super(params);
        this.DOCTYPE = mimeType[params.type || "html"];
    }
    Select(fatherElement, selector, { multi }) {
        if (selector !== null && selector !== undefined) {
            const prop = fatherElement[selector];
            if (prop) {
                return prop;
            } else {
                return fatherElement[
                    multi ? "querySelectorAll" : "querySelector"
                ](selector);
            }
        } else {
            return undefined;
        }
    }
    PreDecode(input) {
        if (typeof input === "string") {
            const parser = new DOMParser();
            return parser.parseFromString(html, this.DOCTYPE);
        } else {
            return input;
        }
    }
}
export default HTMLParser;
